package com.yimo.util;

import com.yimo.chromedriver.FileDesc;
import com.yimo.common.response.BaseResponse;
import lombok.extern.java.Log;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * create by jsm on 2018/10/8
 */
@Log
public class FileDescUtil {
    public static String getPrefix(File f) {
        String name = f.getName();
        return name.substring(name.lastIndexOf("."), name.length());
    }

    public static List <FileDesc> getFileDesc(String path) {
        List <FileDesc> list = new ArrayList <>();
        File f = new File(path);
        if (f != null && f.exists()&&f.isDirectory()) {
            File[] files = f.listFiles();
            if (files != null) {
                for (File file : files) {
                    FileDesc fileDesc = new FileDesc();
                    list.add(fileDesc.build(file));
                }
                return (list);
            }
        }
        return null;
    }
}
